﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xproject.Framework.Core;
using Xproject.Framework.Core.DataContext;
using Xproject.Framework.Core.Repositories;
using Model.ZXBuiness;
using Repository.ZXBuiness;
 
 
namespace Services.ZXBuiness
{
    public class ZXUserInfoServives:Service
    {
        IRepositoryAsync<ZXUserInfo> m_ZXUserInfoRepository;
      

        public ZXUserInfoServives(IDataContextAsync dataContext) : base(dataContext)
        {
            m_ZXUserInfoRepository = m_UnitOfWork.RepositoryAsync<ZXUserInfo>();       
        }

        public ZXUserInfo GetByZXUserId(long zxUserId)
        {
          return   m_ZXUserInfoRepository.GetById(zxUserId);
        }

        public bool UpdateZXUserInfo(ZXUserInfo zx)
        {
            zx.EntityState = EntityState.Modified;
            m_ZXUserInfoRepository.Update(zx);
            return m_UnitOfWork.SaveChanges() == 1;
        }

        public bool RegisterZXUser(string WXUserId,string ZXUserName, long? ZXUserParentId,int? ZXUserSource,string ZXPlatform,int? ZXUserLevel,int zxUserType)
        {
            ZXUserInfo zxuser = new ZXUserInfo();
            zxuser.WX_UserId = WXUserId;
            zxuser.ZX_UserName = ZXUserName;
            zxuser.ZX_UserParentId = ZXUserParentId;
            zxuser.ZX_UserSource = ZXUserSource;
            zxuser.ZX_Platform = ZXPlatform;
            zxuser.ZX_UserLevel = ZXUserLevel;
            zxuser.ZX_UserType = zxUserType;
            zxuser.EntityState = EntityState.Added;
            m_ZXUserInfoRepository.Insert(zxuser);
            return m_UnitOfWork.SaveChanges() == 1;
        }
        /// <summary>
        /// 给其它serviec使用 注册数据库上下文实体
        /// </summary>
        /// <param name="WXUserId"></param>
        /// <param name="ZXUserName"></param>
        /// <param name="ZXUserParentId"></param>
        /// <param name="ZXUserSource"></param>
        /// <param name="ZXPlatform"></param>
        /// <param name="ZXUserLevel"></param>
        public void RegisterZXUserContent(string WXUserId, string ZXUserName, long? ZXUserParentId, int? ZXUserSource, string ZXPlatform, int? ZXUserLevel,int zxUserType,long jifeng)
        {
            ZXUserInfo zxuser = new ZXUserInfo();
            zxuser.WX_UserId = WXUserId;
            zxuser.ZX_UserName = ZXUserName;
            zxuser.ZX_UserParentId = ZXUserParentId;
            zxuser.ZX_UserSource = ZXUserSource;
            zxuser.ZX_Platform = ZXPlatform;
            zxuser.ZX_UserLevel = ZXUserLevel;
            zxuser.ZX_UserType = zxUserType;
            zxuser.JiFeng = jifeng;
            zxuser.EntityState = EntityState.Added;
            zxuser.CreateTime = zxuser.UpdateTime = DateTime.Now;
            m_ZXUserInfoRepository.Insert(zxuser);           
        }
    }
}
